﻿<script>
    $(function () {
        $("#ToolBar").AspLinkToolBar();
        $(".H3Panel").BuildPanel({ excludeIDs: ["SystemOrgAclList"] });
        //构造列表
        CreateLigerGrid(
            $("#SystemOrgAclList"),
            GetCategoryColumns(),
            $.Controller.SystemOrgAcl.GetSystemOrgAclList,
            true);
        //初始化用户名
        $("#divUserName").SheetUser({ Editable: true, Visiable: true, Originate: true, IsMultiple: true });
        //初始化组织名称
        $("#divOUName").SheetUser({ Editable: true, Visiable: true, UserVisible: false, OrgUnitVisible: true, IsMultiple: true });
    })
    //构造列
    function GetCategoryColumns() {
        var userName = $.Lang("SystemOrgAcl.UserName");
        var orgScope = $.Lang("SystemOrgAcl.OrgScope");
        var view = $.Lang("SystemOrgAcl.View");
        var manager = $.Lang("SystemOrgAcl.Manager");
        return [
           { display: userName, name: "UserName", width: '30%' },
           { display: orgScope, name: "OrgScope", width: '50%' },
           { display: view, name: "ViewOrgData", width: '8%', align: "center", render: SetIsDefault },
           { display: manager, name: "Administrator", width: '8%', align: "center", render: SetIsDefault },
           { display: "ObjectID", name: "ObjectID", hide: true }
        ];
    }

    //初始化图标
    function SetIsDefault(rowdata, index, value, column) {
        if (value) {
            return "<img id='" + rowdata.ObjectID + "' name='" + column.columnname + "' value='true' src='" + _PORTALROOT_GLOBAL + "/WFRes/images/checked.gif' value='true' onclick='SetDefault(this)'  style='cursor:pointer;'/>";
        }
        else {
            return "<img id='" + rowdata.ObjectID + "' name='" + column.columnname + "' value='false' src='" + _PORTALROOT_GLOBAL + "/WFRes/images/unChecked.gif' value='false' onclick='SetDefault(this)' style='cursor:pointer;'/>";
        }
    };

    //修改默认值
    function SetDefault(obj) {
        if ($(obj).attr("value") == "false") {
            $(obj).attr("src", _PORTALROOT_GLOBAL + "/WFRes/images/checked.gif");
            $(obj).attr("value", "true");
        }
        else {
            $(obj).attr("src", _PORTALROOT_GLOBAL + "/WFRes/images/unChecked.gif");
            $(obj).attr("value", "false");
        }
        var setSuccess = $.Lang("msgGlobalString.SetSuccess");
        var cancelSuccess = $.Lang("msgGlobalString.SetCancel");
        $.ajax({
            url: $.Controller.SystemOrgAcl.SetDefault,
            data: { id: encodeURI($(obj).attr("id")), isDefault: $(obj).attr("value"), columnName: $(obj).attr("name") },
            type: "post",
            success: function (result) {
                if (result.Success) {
                    if ($(obj).attr("value") == "true")
                        $.H3Dialog.Success({ content: setSuccess });
                    else
                        $.H3Dialog.Success({ content: cancelSuccess });
                } else {
                    if ($(obj).attr("value") == "false") {
                        $(obj).attr("src", _PORTALROOT_GLOBAL + "/WFRes/images/checked.gif");
                        $(obj).attr("value", "true");
                    }
                    else {
                        $(obj).attr("src", _PORTALROOT_GLOBAL + "/WFRes/images/unChecked.gif");
                        $(obj).attr("value", "false");
                    }
                    $.H3Dialog.Warn({ content: $.Lang("msgGlobalString.SaveFailed") });
                }
            }
        });
    };

    //打开新增页面
    function AddFun() {
        var title = $.Lang("SystemOrgAcl.Acl");
        ShowDialog(title, _PORTALROOT_GLOBAL + "/admin/TabMaster.html?url=SysParam/EditSystemOrgAcl.html");
    }

    //删除组织权限
    function DeleteFun(obj) {
        var SelectItemName = $.Lang("msgGlobalString.SelectItem");
        var rows = H3GridManager.getSelectedRows();
        if (rows == null || rows.length == 0) {
            $.H3Dialog.Warn({ content: SelectItemName });
            return false;
        }
        var ids = "";
        for (var i = 0; i < rows.length; i++) {
            ids = ids + rows[i].ObjectID + ",";
        }
        if (ConfirmDel(obj)) {
            $.ajax({
                url: $.Controller.SystemOrgAcl.DelSystemOrgAcl,
                type: 'post',
                dataType: "json",
                data: { ids: ids },
                success: function (result) {
                    if (result.Success) {
                        ReloadGrid();
                        $.H3Dialog.Success({ content: $.Lang("msgGlobalString.DeleteSucced") });
                    } else {
                        $.H3Dialog.Warn({ content: result.Message });
                    }
                }
            });
        }
    }

    function ReloadGrid() {
        var manager = $("#SystemOrgAclList").ligerGetGridManager();
        manager.reload(); 
    }
    //申明过滤条件对象
    var SeachParams = function () {
        var params = {};
        params.UserName = [];
        params.OUName = [];
        return params;
    }
    //根据条件帅选
    function QueryFunList() {
        // ;
        var divUserName = $("#divUserName").SheetUIManager().GetValue();
        var divOUName = $("#divOUName").SheetUIManager().GetValue();

        var seach = SeachParams();
        seach.UserName = divUserName;
        seach.OUName = divOUName;

        CreateLigerGrid(
               $("#SystemOrgAclList"),
               GetCategoryColumns(),
          $.Controller.SystemOrgAcl.GetSystemOrgAclListParams,
           true,
           null,
            null,
            null,
            null,
           seach
        );
    }
</script>
<div id="ToolBar">
    <a href="#" id="lnkAdd" data-icon="fa fa-plus" onclick="AddFun()" data-lang="GlobalButton.Add"></a>
    <a onclick=" DeleteFun(this);" data-icon="fa fa-minus" href="javascript:void(0)" data-lang="GlobalButton.Delete">删除</a>
</div>
<div class="H3Panela">
    <table class="tableList">
        <tr>
            <td style="width:8%;padding-left:8px;" data-lang="GlobalButton.UserName">用户名</td>
            <td style="width:20%;">
                <div id="divUserName" style="width:90%;height:80%"></div>
            </td>
            <td style="width:8%;" data-lang="GlobalButton.OUName">组织名称</td>
            <td style="width:20%;">
                <div id="divOUName" style="width:90%;height:80%"></div>
            </td>
            <td style="width:20%;">
                <a onclick="QueryFunList()" href="#" data-lang="GlobalButton.Search" data-icon="fa fa-plus">查询</a>
            </td>
        </tr>
    </table>
</div>
<div class="H3Panel">
    <div id="SystemOrgAclList"></div>
</div>